//package com.cjm.one.common.config.sms;
//import com.cjm.one.common.config.sms.EmailProperties;
//import jakarta.annotation.Resource;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.mail.javamail.JavaMailSender;
//import org.springframework.mail.javamail.JavaMailSenderImpl;
//
//import java.util.Properties;
//
//// MailConfig.java
//@Configuration
//@Slf4j
//public class MailConfig {
//
//    @Resource
//    private EmailProperties emailProperties; // 修正拼写为 Properties
//
//    @Bean
//    public JavaMailSender javaMailSender() {
//
//        log.info("初始化邮件发送器...");
//        log.info("邮件服务器地址: {}", emailProperties.getHost());
//        log.info("邮件服务器端口: {}", emailProperties.getPort());
//        log.info("邮件服务器用户名: {}", emailProperties.getUsername());
//        log.info("邮件服务器密码: {}", emailProperties.getPassword());
//        log.info("邮件服务器协议: {}", emailProperties.getProtocol());
//        log.info("邮件服务器属性: {}", emailProperties.getProperties());
//
//        JavaMailSenderImpl sender = new JavaMailSenderImpl();
//        sender.setHost(emailProperties.getHost());
//        sender.setPort(emailProperties.getPort());
//        sender.setUsername(emailProperties.getUsername());
//        sender.setPassword(emailProperties.getPassword());
//
//        // 补充协议层配置
//        sender.setProtocol(emailProperties.getProtocol());
//
//        // 强制设置编码（防止中文乱码）
//        sender.setDefaultEncoding("UTF-8");
//
//        // 显式配置Properties
//        Properties props = new Properties();
//        props.putAll(emailProperties.getProperties());
//        sender.setJavaMailProperties(props);
//
//        return sender;
//    }
//}
